package cn.webrx.coll;/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * <p>Project: jse2204 - cn.webrx.coll.ArrayList5
 * <p>Powered by webrx On 2022-09-19 09:51:06
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ArrayList5 {


    public static void main(String[] args) {
        //集合字符串乱升降
        //1建立集合
        List<String> list = new ArrayList<>(List.of("java", "c", "c++", "go", "ruby", "javascript", "python"));
        System.out.println("排序前："+list);

        //2乱
        Collections.shuffle(list);
        Collections.shuffle(list);
        System.out.println("排乱序："+list);

        //3升
        Collections.sort(list);
        System.out.println("排升序："+list);

        //4降
        Collections.sort(list,(a,b)->b.compareTo(a));
        //Collections.sort(list, Comparator.reverseOrder());
        System.out.println("排降序："+list);

        //根据字符个数升序 降序
        Collections.sort(list,(a,b)->a.length()-b.length());
        System.out.println("排升序："+list);
        Collections.sort(list,(a,b)->b.length()-a.length());
        System.out.println("排降序："+list);
    }


    public static void num(String[] args) {
        //cn.webrx.coll.User u = new cn.webrx.coll.User(100,"李四");
        //System.out.println(u);

        //集合数字排序乱升降
        //1.建立集合
        List<Integer> list = new ArrayList<>(List.of(10, 5, 2, 0, 3, 1, 9, 25, 18));
        System.out.println(list);

        //2.乱顺序
        Collections.reverse(list);
        System.out.println(list);
        Collections.shuffle(list);
        System.out.println(list);

        //3.升序
        Collections.sort(list);
        System.out.println("排升序:" + list);

        //4.降序
        Collections.sort(list, (a, b) -> b - a);
        System.out.println("排降序:" + list);

    }
}
